/*
 * vim:fdm=marker:
 */
#include <stdio.h>
#include <stdlib.h>

static void
swap_int(int* a, int* b)
{
	int T;
	T  = *a;
	*a = *b;
	*b =  T;
}

static void
Heap_sort__sift_down(int * array, int start, int end)
{
	int root = start,
	    child,
	    swap;

	while (root * 2 + 1 <= end) {
		child = root * 2 + 1;
		swap = root;

		if (array[swap] < array[child])
			swap = child;

		if (child + 1 <= end && array[swap] < array[child + 1])
			swap = child + 1;

		if (swap != root) {
			swap_int(&array[root], &array[swap]);
			root = swap;
		} else {
			return;
		}
	}
}

static void
Heap_sort__heapify(int* array, int size)
{
	int start = size / 2 - 1;

	while (start >= 0) {
		Heap_sort__sift_down(array, start--, size - 1);
	}
}

void
Heap_sort(int *array, int size)
{
	int end = size - 1;

	Heap_sort__heapify(array, size);

	while (end > 0) {
		swap_int(&array[end], &array[0]);
		Heap_sort__sift_down(array, 0, --end);
	}
}

int
main(void)
{
	static int n, array[500000];
	register int i;

	scanf("%d\n", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &array[i]);

	Heap_sort(array, n);

	for (i = 0; i < n; i++)
		printf("%d ", array[i]);
	fputc('\n', stdout);

	return 0;
}
